<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="public::head('投票表决')">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8"></meta>

</head>
<body style="padding-top:50px;">
<input type="hidden" th:value="${session.Id}" id="id"/>
<input type="hidden" th:value="${session.Type}" id="Type"/>

<div th:replace="public/top_vote::top"></div>

<div id="Votelist">
    <div th:replace="vote/edit_shiyongyuanze::editShiyongyuanze"></div>
    <div class="primary-title" style="height:80px">
        <div style="margin-top:15px;text-align: center;font-size:24px;">
            <label  style="margin-left: 20px; ">{{xiangmu.xiangmuname}}</label>
        </div>
        <div style="text-align: center;font-size:16px">
            <label  style="margin-left: 50px; "><!--您之前已经勾选{{yitongyishu}}个品规，-->本表共 {{total}}个品种，已表决<font color="green">{{tongyishu}}</font>个品种，剩余{{butongyishu}}个品种</label>
            <!--<label  style="margin-left: 50px; ">共1849个品规，已表决<font color="green">2</font>个品规，剩余1847个品规</label>-->
            <input v-if="!issubmited" type="button" class="btn btn-sm btn-primary" style="width: 60px" value="提交" @click="tosubmit()">
            <input v-if="issubmited" type="button" class="btn btn-sm btn-success" disabled style="width: 60px" value="已提交" @click="tosubmit()">
        </div>
        <!-- <div style="text-align: center;font-size:18px;padding-top: 10px">
           <label  style="margin-left: 20px;">筛选条件：</label> <select class="select-form-control" v-model="tiaojian">
            <option value="">&#45;&#45; 请选择 &#45;&#45;</option>
            <option v-if="xiangmu.xiangmuleixing==10" value="封闭试剂">封闭试剂</option>
            <option value="一个品牌">一个品牌</option>
            <option v-if="xiangmu.xiangmuleixing==11" value="两个品牌">两个品牌</option>
            <option v-if="xiangmu.xiangmuleixing==11" value="专机专用">专机专用</option>
            </select>
            <button class="btn btn-info" @click="chaxulist()" style="margin-left:15px;">查询</button>
            <button class="btn btn-danger" @click="remove()" style="margin-left:15px;">重置条件</button>
            <button class="btn btn-success" @click="toVoteSure()" style="margin-left:15px;">一键全选筛选条件</button>
        </div>-->
        <!--<div style="font-size:12px; align-items: center; justify-content: center">

        </div>-->
    </div>

    <!--<div style="height: 30px"></div>-->

    <div class="primary-content">

        <div id="List">
        </div>

        <div v-if="!show" style="text-align:center;width:100%;">查无数据</div>

        <div v-if="show" class="my-page-navigation">
            <button class="btn btn-default" v-on:click="SetPageIndex">首页</button>
            <button class="btn btn-default" v-on:click="SetPageIndexPrePage">上一页</button>
            <span v-text="pageIndex + '  /  ' + pageCount"></span>
            <span v-text="'共' + recordCount + '条品种'"></span>
            <button class="btn btn-default" v-on:click="SetPageIndexNextPage">下一页</button>
            <button class="btn btn-default" v-on:click="SetPageEnd">尾页</button>
            <span>跳到第</span>
            <input type="text" class="form-control" style="width: 80px;display:inline-block;"  v-model="inputPageIndexValue" v-on:keyup.enter="JumpPage">
            <span>页</span>
            <button class="btn btn-default" v-on:click="JumpPage">跳</button>
        </div>

    </div>



</div>

</body>
<style>
    table{
        border:1px solid #e6e6e6;
       /* line-height: 5vh;*/
        color:#666666;
        font-size: 12px;
    }
    table {
        border-collapse: collapse;
        width: 100%;
    }
    td {
        padding:5px;
        border:1px solid #e6e6e6;
        font-size: 12px;
    }
    .table-head{padding-right:17px;background-color: #CDCDCD;color:#000;height:50px;}
    .table-body{width:100%; height:550px;overflow-y:scroll;}
    .table-head table,.table-body table{width:100%;}
  /*  .table-body table tr:nth-child(2n+1){background-color:#f2f2f2;}*/

    .table-body table tr:hover {
        background-color:rgb(240, 249, 228);
        transition: .2s;
    }
</style>
<script th:src="@{/js/vote/list_shiji_vote.js}"></script>

<script type="text/javascript">
    var ID = $("#id").val();

    var dragModal={
        mouseStartPoint:{"left":0,"top":  0},
        mouseEndPoint : {"left":0,"top":  0},
        mouseDragDown : false,
        basePoint : {"left":0,"top":  0},
        moveTarget:null,
        topleng:0
    }
    $(document).on("mousedown",".modal-header",function(e){
        //webkit内核和火狐禁止文字被选中
        $('body').addClass('select')
        //ie浏览器禁止文字选中
        document.body.onselectstart=document.body.ondrag=function(){
            return false;
        }
        if($(e.target).hasClass("close"))//点关闭按钮不能移动对话框
            return;
        dragModal.mouseDragDown = true;
        dragModal.moveTarget = $(this).parent().parent();
        dragModal.mouseStartPoint = {"left":e.clientX,"top":  e.pageY};
        dragModal.basePoint = dragModal.moveTarget.offset();
        dragModal.topLeng=e.pageY-e.clientY;
    });
    $(document).on("mouseup",function(e){
        dragModal.mouseDragDown = false;
        dragModal.moveTarget = undefined;
        dragModal.mouseStartPoint = {"left":0,"top":  0};
        dragModal.basePoint = {"left":0,"top":  0};
    });
    $(document).on("mousemove",function(e){
        if(!dragModal.mouseDragDown || dragModal.moveTarget == undefined)return;
        var mousX = e.clientX;
        var mousY = e.pageY;
        if(mousX < 0)mousX = 0;
        if(mousY < 0)mousY = 25;
        dragModal.mouseEndPoint = {"left":mousX,"top": mousY};
        var width = dragModal.moveTarget.width();
        var height = dragModal.moveTarget.height();
        var clientWidth=document.body.clientWidth
        var clientHeight=document.body.clientHeight;
        if(dragModal.mouseEndPoint.left<dragModal.mouseStartPoint.left - dragModal.basePoint.left){
            dragModal.mouseEndPoint.left=0;
        }
        else if(dragModal.mouseEndPoint.left>=clientWidth-width+dragModal.mouseStartPoint.left - dragModal.basePoint.left){
            dragModal.mouseEndPoint.left=clientWidth-width-38;
        }else{
            dragModal.mouseEndPoint.left =dragModal.mouseEndPoint.left-(dragModal.mouseStartPoint.left - dragModal.basePoint.left);//移动修正，更平滑

        }
        if(dragModal.mouseEndPoint.top-(dragModal.mouseStartPoint.top - dragModal.basePoint.top)<dragModal.topLeng){
            dragModal.mouseEndPoint.top=dragModal.topLeng;
        }else if(dragModal.mouseEndPoint.top-dragModal.topLeng>clientHeight-height+dragModal.mouseStartPoint.top - dragModal.basePoint.top){
            dragModal.mouseEndPoint.top=clientHeight-height-38+dragModal.topLeng;
        }
        else{
            dragModal.mouseEndPoint.top = dragModal.mouseEndPoint.top - (dragModal.mouseStartPoint.top - dragModal.basePoint.top);
        }
        dragModal.moveTarget.offset(dragModal.mouseEndPoint);
    });
    $(document).on('hidden.bs.modal','.modal',function(e){
        $('.modal-dialog').css({'top': '0px','left': '0px'})
        $('body').removeClass('select')
        document.body.onselectstart=document.body.ondrag=null;
    })
    $(function() {
        if(ID==""){
            alert("请先登录！");
            location.href='../main/login';
        }
    });

    function topinpaiVote(ppxiangmuId,ppId,ppPinzhong,ppPinpai){
        var ppResult="0";
        var xinghaoIds = ppId.split(",");

        console.log(xinghaoIds);
        if ($("#checkbox_"+ppPinzhong+"_"+ppPinpai+"").is(":checked"))
            ppResult = "1";
        console.log(xinghaoIds.length);
        layer.open({type: 3});
        $.post('/shijijieguo/toupiao', {
            xiangmuid: ppxiangmuId,
            id: ppId,
            pinzhong:ppPinzhong,
            pinpai:ppPinpai,
            userid:$("#id").val(),
            result: ppResult,
            rdm: Math.random()
        }, function (ppData) {
            layer.closeAll("loading");
            if (ppData != null) {
                if (ppData.result == "1") {
                    vote.getResultCount();
                   /* window.location.hash = "#div_"+ppPinzhong+"_"+ppPinpai+"";*/
                    if (ppResult == "1"){
                        for (var i = 0; i < xinghaoIds.length; i++) {
                            $("#div_"+xinghaoIds[i]+"").html("<input style=\"height:20px;width: 20px;\" onclick=\"toVote('"+ppxiangmuId+"','"+xinghaoIds[i]+"','"+xinghaoIds+"','"+ppPinzhong+"','"+ppPinpai+"')\" id='checkbox_"+xinghaoIds[i]+"' class='cbcss' checked type=\"checkbox\">");
                        }
                        $("#div_"+ppPinzhong+"_"+ppPinpai+"").html("<input style=\"height:20px;width: 20px;\" onclick=\"topinpaiVote('"+ppxiangmuId+"','"+ppId+"','"+ppPinzhong+"','"+ppPinpai+"')\" id='checkbox_"+ppPinzhong+"_"+ppPinpai+"' class='cbcss' checked type=\"checkbox\">");
                    } else {
                        for (var j = 0; j < xinghaoIds.length; j++) {
                            $("#div_"+xinghaoIds[j]+"").html("<input style=\"height:20px;width: 20px;\" onclick=\"toVote('"+ppxiangmuId+"','"+xinghaoIds[j]+"','"+xinghaoIds+"','"+ppPinzhong+"','"+ppPinpai+"')\" id='checkbox_"+xinghaoIds[j]+"' class='cbcss' type=\"checkbox\">");
                        }
                        $("#div_"+ppPinzhong+"_"+ppPinpai+"").html("<input style=\"height:20px;width: 20px;\" onclick=\"topinpaiVote('"+ppxiangmuId+"','"+ppId+"','"+ppPinzhong+"','"+ppPinpai+"')\" id='checkbox_"+ppPinzhong+"_"+ppPinpai+"' class='cbcss' type=\"checkbox\">");
                    }

                } else {
                    layer.alert(ppData.message);
                    $("#div_"+ppPinzhong+"_"+ppPinpai+"").html("<input style=\"height:20px;width: 20px;\" onclick=\"topinpaiVote('"+ppxiangmuId+"','"+ppId+"','"+ppPinzhong+"','"+ppPinpai+"')\" id='checkbox_"+ppPinzhong+"_"+ppPinpai+"' class='cbcss' type=\"checkbox\">");
                }
            }
        }, "json");

    }

    function toVote(ppxiangmuId,ppId,ppIds,ppPinzhong,ppPinpai){
        var ppResult="0";
        var pppinpaiResult = "0";
        var xinghaoIds = ppIds.split(",");

        console.log(xinghaoIds)
        if ($("#checkbox_" + ppId + "").is(":checked")){
            ppResult = "1";
        }
        for (var i = 0; i<xinghaoIds.length; i++) {
            console.log(xinghaoIds[i]);
            if($("#checkbox_" + xinghaoIds[i] + "").is(":checked")){
                pppinpaiResult="1";
                break;
            }
        }
        layer.open({type: 3});
        $.post('/shijijieguo/toupiao', {
            xiangmuid: ppxiangmuId,
            id: ppId,
            pinzhong:ppPinzhong,
            pinpai:ppPinpai,
            userid:$("#id").val(),
            result: ppResult,
            rdm: Math.random()
        }, function (ppData) {
            layer.closeAll("loading");
            if (ppData != null) {
                if (ppData.result == "1") {
                    vote.getResultCount();
                    if (ppResult == "1"){
                        $("#div_"+ppId+"").html("<input style=\"height:20px;width: 20px;\" onclick=\"toVote('"+ppxiangmuId+"','"+ppId+"','"+xinghaoIds+"','"+ppPinzhong+"','"+ppPinpai+"')\" id='checkbox_"+ppId+"' class='cbcss' checked type=\"checkbox\">");
                        $("#div_"+ppPinzhong+"_"+ppPinpai+"").html("<input style=\"height:20px;width: 20px;\" onclick=\"topinpaiVote('"+ppxiangmuId+"','"+xinghaoIds+"','"+ppPinzhong+"','"+ppPinpai+"')\" id='checkbox_"+ppPinzhong+"_"+ppPinpai+"' class='cbcss' checked type=\"checkbox\">");
                    } else {
                        $("#div_"+ppId+"").html("<input style=\"height:20px;width: 20px;\" onclick=\"toVote('"+ppxiangmuId+"','"+ppId+"','"+xinghaoIds+"','"+ppPinzhong+"','"+ppPinpai+"')\" id='checkbox_"+ppId+"' class='cbcss' type=\"checkbox\">");
                        if (pppinpaiResult == "0"){
                            $("#div_"+ppPinzhong+"_"+ppPinpai+"").html("<input style=\"height:20px;width: 20px;\" onclick=\"topinpaiVote('"+ppxiangmuId+"','"+xinghaoIds+"','"+ppPinzhong+"','"+ppPinpai+"')\" id='checkbox_"+ppPinzhong+"_"+ppPinpai+"' class='cbcss' type=\"checkbox\">");
                        }
                        else
                            $("#div_"+ppPinzhong+"_"+ppPinpai+"").html("<input style=\"height:20px;width: 20px;\" onclick=\"topinpaiVote('"+ppxiangmuId+"','"+xinghaoIds+"','"+ppPinzhong+"','"+ppPinpai+"')\" id='checkbox_"+ppPinzhong+"_"+ppPinpai+"' class='cbcss' checked type=\"checkbox\">");

                    }

                } else {
                    layer.alert(ppData.message);
                    $("#div_"+ppId+"").html("<input style=\"height:20px;width: 20px;\" onclick=\"toVote('"+ppxiangmuId+"','"+ppId+"','"+xinghaoIds+"','"+ppPinzhong+"','"+ppPinpai+"')\" id='checkbox_"+ppId+"' class='cbcss' type=\"checkbox\">");
                    $("#div_"+ppPinzhong+"_"+ppPinpai+"").html("<input style=\"height:20px;width: 20px;\" onclick=\"topinpaiVote('"+ppxiangmuId+"','"+xinghaoIds+"','"+ppPinzhong+"','"+ppPinpai+"')\" id='checkbox_"+ppPinzhong+"_"+ppPinpai+"' class='cbcss' type=\"checkbox\">");

                }
            }
        }, "json");

    }

    function toModify(ppDetailid,ppPinzhong,ppPinpai){
        $('#editShiyongyuanzeModal').modal();
        $("#myModalLabel_shiyongyuanze").html("品种序号："+ppPinzhong+"，品牌序号："+ppPinpai);
        vote.detailid=ppDetailid;
        vote.pinzhong=ppPinzhong;
        vote.pinpai=ppPinpai;
        vote.bindShiyongyuanze();
        // vote.openSelect();
    }



</script>
<style>
    a {
        text-decoration: none;
        color:#333;
    }
    /*正常的未被访问过的链接*/
    a:link {
        text-decoration: none;
    }
    /*已经访问过的链接*/
    a:visited {
        text-decoration: none;
    }
    /*鼠标划过(停留)的链接*/
    a:hover {
        text-decoration: none;
    }
    /* 正在点击的链接*/
    a:active {
        text-decoration: none;
    }
</style>
</html>